package com.hzqy.service.mysong;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.hzqy.persistence.dao.mysong.MySongSheetDao;
import com.hzqy.service.core.GenericServiceBean;
import com.hzqy.web.vo.MySongSheetVo;
import com.hzqy.web.vo.PmsUserVo;

@Service
public class MySongSheetServiceBean extends GenericServiceBean<PmsUserVo,MySongSheetDao, Integer> {
	private static final long serialVersionUID = 1L;
	protected final Logger LOG = LoggerFactory.getLogger(getClass());
	
	@Resource
	private MySongSheetDao mySongSheetDao;
	
	@Override
	public MySongSheetDao getEntityDao() {
		return mySongSheetDao;
	}
	
	
	public MySongSheetVo selectMySongSheetVoInfo(MySongSheetVo mySongSheetVo) {
		Map<String,Object> map = new HashMap<String,Object >();
		map.put("f_mss_serverid", mySongSheetVo.getF_mss_serverid());
		MySongSheetVo mssv = mySongSheetDao.selectMySongSheetVoInfo(map);
		/*
		 * if(mssv == null) { mssv = new MySongSheetVo(); }
		 */
		return mssv;
	}
	
	public int insertOrUpdate(MySongSheetVo mySongSheetVo) {
		int flag = 0;
		Map<String,Object> map = new HashMap<String,Object >();
		map.put("f_mss_serverid", mySongSheetVo.getF_mss_serverid());
		MySongSheetVo mssv = mySongSheetDao.selectMySongSheetVoInfo(map);
		if(mssv!=null) { //存在，update,
			if(mySongSheetVo.getF_mss_introduce_count() == 1) {
				mySongSheetVo.setF_mss_introduce_count(mssv.getF_mss_introduce_count()+1);
			}
			flag = mySongSheetDao.updataMySongSheetInfo(mySongSheetVo);
		}else {//不存在，insert
			flag = mySongSheetDao.insertMySongSheetInfo(mySongSheetVo);
		}
		return flag ;
	}
	 
}
